/*
 * kVistaPlanificacio.java
 *
 * Created on 28 de mayo de 2008, 17:45
 */
package vistes;

import java.awt.event.ActionListener;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author  Josep Marti
 */
public class VistaPlanificacio extends javax.swing.JPanel {

    /** Creates new form kVistaPlanificacio */
    public VistaPlanificacio() {
        initComponents();
    }

    public void setLlistaPlans(String[] llistaPlanificacions) {
        /* Col·loca la llistaPlanificacions dins la JList llistaPlanificacionsV */
        llistaPlanificacionsV.setListData(llistaPlanificacions);
    }

    String getGraellaSelected() {
        /* Retorna un String que identifica una Emissio */
        if (!(graella.getSelectedColumn() == 0 ||  graella.getSelectedColumn() == -1 || graella.getSelectedRow() == -1))
        return (String) graella.getValueAt(graella.getSelectedRow(), graella.getSelectedColumn());
        else
            return null;
    }

    public int getIndexsSelected() {
        return llistaPlanificacionsV.getSelectedIndex();
    }

    String getPlanSelected() {

        String pla = (String) llistaPlanificacionsV.getSelectedValue();
        return pla;
    }

    public void setGraella() {

        String[][] graellaAuxiliar = new String[144][8];
        graella.setModel(new javax.swing.table.DefaultTableModel(
                graellaAuxiliar,
                new String[]{
            "Hora", "Dilluns", "Dimarts", "Dimecres", "Dijous", "Divendres", "Dissabte", "Diumenge"
        }));

    }

    public void setActions(ActionListener actions[], ListSelectionListener lPlanificacions) {

        llistaPlanificacionsV.getSelectionModel().addListSelectionListener(lPlanificacions);
        botoNovaPlanificacio.addActionListener(actions[0]);
        botoSetmanaAnterior.addActionListener(actions[1]);
        botoSetmanaSeguent.addActionListener(actions[2]);
        botoAnular.addActionListener(actions[3]);
        veureResum.addActionListener(actions[4]);
    }

    void pintarGraella(String[][] grill) {

        for (int i = 0; i < 144; i++) {
            for (int j = 0; j < 8; j++) {
                graella.setValueAt(grill[i][j], i, j);
            }
        }
    }

    void setSelectPlan(int planSelected) {
        llistaPlanificacionsV.setSelectedIndex(planSelected);
    }

   void setSetmana(String setmana) {
        botoSetmana.setText(setmana);
    }

    void setPreu(double preu) {
        preuTotalV.setText(""+(float) preu);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        graella = new javax.swing.JTable();
        botoNovaPlanificacio = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        llistaPlanificacionsV = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        preuTotalV = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        botoAnular = new javax.swing.JButton();
        botoSetmanaAnterior = new javax.swing.JButton();
        botoSetmanaSeguent = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        botoSetmana = new javax.swing.JTextPane();
        veureResum = new javax.swing.JButton();

        graella.setModel(new javax.swing.table.DefaultTableModel(
            new Object [144][8],
            new String [] {
                "Hora","Dilluns", "Dimarts", "Dimecres", "Dijous","Divendres", "Dissabte", "Diumenge"
            }
        ));
        graella.setColumnSelectionAllowed(true);
        graella.setInheritsPopupMenu(true);
        graella.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(graella);
        graella.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        botoNovaPlanificacio.setFont(new java.awt.Font("Bitstream Vera Sans", 1, 12));
        botoNovaPlanificacio.setText("CREAR NOVA PLANIFICACIO");

        jScrollPane2.setViewportView(llistaPlanificacionsV);

        jLabel3.setText("Preu Total:");

        preuTotalV.setEditable(false);

        jLabel4.setFont(new java.awt.Font("Bitstream Vera Sans", 1, 10));
        jLabel4.setText("Llista Planificacions:");

        botoAnular.setText("Anul·lar Programa");

        botoSetmanaAnterior.setText(" << Setmana anterior");

        botoSetmanaSeguent.setText("Setmana següent >>");

        jLabel1.setText("€");

        botoSetmana.setEditable(false);
        botoSetmana.setAlignmentX(1.0F);
        botoSetmana.setAlignmentY(1.0F);
        jScrollPane3.setViewportView(botoSetmana);

        veureResum.setText("Llista");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(23, 23, 23)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 655, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(botoSetmanaAnterior, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(botoSetmanaSeguent)
                                .addGap(35, 35, 35)
                                .addComponent(veureResum, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGap(41, 41, 41))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(preuTotalV, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 301, Short.MAX_VALUE)
                        .addComponent(botoAnular)
                        .addGap(138, 138, 138)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botoNovaPlanificacio, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                                .addGap(31, 31, 31))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(jLabel4)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(veureResum)
                        .addComponent(botoSetmanaSeguent))
                    .addComponent(botoSetmanaAnterior)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(botoAnular)
                    .addComponent(preuTotalV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(86, 86, 86))
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botoNovaPlanificacio, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(94, 94, 94))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botoAnular;
    private javax.swing.JButton botoNovaPlanificacio;
    private javax.swing.JTextPane botoSetmana;
    private javax.swing.JButton botoSetmanaAnterior;
    private javax.swing.JButton botoSetmanaSeguent;
    private javax.swing.JTable graella;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList llistaPlanificacionsV;
    private javax.swing.JTextField preuTotalV;
    private javax.swing.JButton veureResum;
    // End of variables declaration//GEN-END:variables
}
